import { defineStore } from 'pinia'
import { mockQualityAPI } from '@/api/quality'

export const useQualityStore = defineStore('quality', {
  state: () => ({
    exceptions: [],
    records: [],
    deductions: [],
    additions: [],
    stats: {
      pendingCount: 0,
      processedCount: 0,
      totalDeductions: 0,
      totalAdditions: 0
    }
  }),

  actions: {
    async fetchExceptionList(params: any) {
      const response = await mockQualityAPI.getExceptionList(params)
      return response.data
    },

    async processException(data: any) {
      const response = await mockQualityAPI.processException(data)
      return response.data
    },

    async fetchQualityRecords(params: any) {
      const response = await mockQualityAPI.getQualityRecords(params)
      return response.data
    },

    async fetchDeductionRecords(params: any) {
      const response = await mockQualityAPI.getDeductionRecords(params)
      return response.data
    },

    async fetchAdditionRecords(params: any) {
      const response = await mockQualityAPI.getAdditionRecords(params)
      return response.data
    },

    async createDeduction(data: any) {
      const response = await mockQualityAPI.createDeduction(data)
      return response.data
    },

    async createAddition(data: any) {
      const response = await mockQualityAPI.createAddition(data)
      return response.data
    },

    // 获取投递记录列表
    async fetchDeliveryRecords(params: any) {
      const response = await mockQualityAPI.getUserDeliveryRecords(params) as any
      return response.data
    },

    // 创建异常
    async createException(data: any) {
      const response = await mockQualityAPI.createException(data)
      return response.data
    }
  }
})
